package com.hisysteTopet.hisystepet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisysteTopet.hisystepet.bean.Pet;
import com.hisysteTopet.hisystepet.bean.PetLifeGoods;
import com.hisysteTopet.hisystepet.mapper.provider.updatePetLifeGoodsMessage;
import com.hisysteTopet.hisystepet.mapper.provider.updatePetMessage;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PetLifeGoodsMapper extends BaseMapper<PetLifeGoods> {


    // 查询所有宠物
    @Select("select * from pet_life_goods")
    public List<PetLifeGoods> findAll();

    // 修改宠物的库存
    @Update("UPDATE pet_life_goods SET price_num = price_num - #{priceNumber} WHERE price_id = #{priceId};")
    public  void updateToPriceNum(Integer priceNumber,Integer priceId);

    // 查询宠物的库存
    @Select(" SELECT * FROM pet_life_goods WHERE pet_life_goods.`price_id` = #{priceId} ")
    public PetLifeGoods selectToPriceId(Integer priceId);

    // 修改宠物的信息
    @UpdateProvider(type = updatePetLifeGoodsMessage.class, method = "updatePetLifeGoodsMessage")
    public void updatePetLifeGoodsMessage(PetLifeGoods petLifeGoods);

    // 删除宠物的信息
    @Delete("DELETE FROM pet_life_goods WHERE price_id = #{priceId}")
    public void deletePetLifeGoodsMessageById(String priceId);

    // 管理员修改宠物的库存
    @Update(" UPDATE pet_life_goods SET pet_life_goods.`price_num` = #{lifeGoodsNumber}" +
            " WHERE pet_life_goods.`price_id` = #{lifeGoodsId}")
    public  void updateToPetLifeGoodsNumByAdmin(Integer lifeGoodsNumber,Integer lifeGoodsId);

    // 添加宠物生活用品
    @Insert("INSERT INTO pet_life_goods(pet_life_goods.`price_name`,pet_life_goods.`url`," +
            "pet_life_goods.`introduce`,pet_life_goods.`price`,pet_life_goods.`price_num`)" +
            "           VALUE(#{priceName},#{url},#{introduce},#{price},#{num})")
    public  void insertLifeGoods(String priceName,String url,
                           String introduce,Integer price,Integer num);
}
